package com.warren.scheduler.job;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.warren.biz.entity.OutStock;
import com.warren.biz.service.OutStockService;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author warren
 * @create 2021-05-11 16:35
 * @Description
 */

public class DelStockJob extends QuartzJobBean {

    @Resource
    private OutStockService outStockService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("+++++++++++++++++++++++++++++++++++++++++删除物资");

        JobDetail jobDetail = jobExecutionContext.getJobDetail();
        System.out.println(jobDetail.getKey().getName());

        QueryWrapper<OutStock> qw = new QueryWrapper<>();
        qw.like("status",1);
        List<OutStock> stocks = outStockService.findStockInRubbish(qw);

        for (int i = 0; i < stocks.size(); i++) {
            OutStock stock = stocks.get(i);
            outStockService.delete(stock.getId(),stock.getOutNum());
        }
    }
}
